<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html,
      body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #map_container {
        width: 100%;
        height: 100%;
        margin: 0;
      }
    </style>
    <script
      type="text/javascript"
      src="https://api.map.baidu.com/api?type=webgl&v=1.0&ak=G1LFyjrNGIkns5OfpZnrCGAKxpycPLwb"
    ></script>
    <script src="https://mapv.baidu.com/gl/examples/static/common.js"></script>
    <script src="https://mapv.baidu.com/build/mapv.js"></script>
    <script src="https://code.bdstatic.com/npm/mapvgl@1.0.0-beta.54/dist/mapvgl.min.js"></script>
    <title>地图展示</title>
  </head>
  <body>
    <div id="map_container"></div>
    <script type="text/javascript">
    
      // 百度地图mapv开发流程是怎样的?

      // details

      /*
        1.引入js库
          *百度地图js
          *百度地图mapv
          *百度地图mapvgl
        2.编写容器组件
        3.初始化Map对象
        4.初始化绘制数据，数据格式为
          [{
            geometry: {
              type: 'Point',
              coordinates: [x, y]
            },
            properties: {
              count: Math.random() * 100
              // other properties...
            }
          }, {
            // other data...
          }]

        5.初始化mapvgl.View 图层管理器
        6.初始化mapvgl.Intensity 数据显示强度
        7.初始化mapvgl.PointLayer 图层
        8.调用view.addLayer添加图层到图层管理器
        9.调用mapvgl.PointLayer.setData 关联图层和数据
      */


      let map = initMap({
        tilt: 0,
        heading: 0,
        center: [103.438656, 25.753594],
        zoom: 8,
        style: snowStyle,
        skyColors: [
          // 地面颜色
          'rgba(226, 237, 248, 0)',
          // 天空颜色
          'rgba(186, 211, 252, 1)'
        ]
      });

      setData(initData());

      function initData () {
        let data = [];
        let citys = [
          '北京', '天津', '上海', '重庆', '石家庄', '太原', '呼和浩特', '哈尔滨', '长春',
          '沈阳', '济南', '南京', '合肥', '杭州', '南昌', '福州', '郑州', '武汉', '长沙', '广州',
          '南宁', '西安', '银川', '兰州', '西宁', '乌鲁木齐', '成都', '贵阳', '昆明', '拉萨', '海口'
        ];
        let randomCount = 700;

        // 构造数据
        while (randomCount--) {
          let cityCenter = mapv.utilCityCenter.getCenterByCityName(citys[parseInt(Math.random() * citys.length, 10)]);
          data.push({
            geometry: {
              type: 'Point',
              coordinates: [cityCenter.lng - 2 + Math.random() * 4, cityCenter.lat -2 + Math.random() * 4]
            },
            properties: {
              count: Math.random() * 100
            }
          });
        }

        return data;
      }

      function setData (data) {
        let view = new mapvgl.View({map: map});

      let intensity = new mapvgl.Intensity({
        max: 100,
        min: 0,
        gradient: {
          0: 'rgb(25, 66, 102, 0.8)',
					0.3: 'rgb(145, 102, 129, 0.8)',
					0.7: 'rgb(210, 131, 137, 0.8)',
					1: 'rgb(248, 177, 149, 0.8)'
        },
        maxSize: 30,
        minSize: 5
      });

      let pointLayer = new mapvgl.PointLayer({
        blend: 'lighter',
        size: function (data) {
          return intensity.getSize(data.properties.count);
        },
        color: function (data) {
          return intensity.getColor(data.properties.count);
        }
      });

        view.addLayer(pointLayer);
        pointLayer.setData(data);

      }
    </script>
  </body>
</html>
